home *** CD-ROM | disk | FTP | other *** search
/ InterCD 1999 June / june_1999.iso / Palm / Business / TC Logger / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-09  |  3.8 KB  |  137 lines

  1. #include <Common.h>
  2. #include <System/SysAll.h>
  3. #include <UI/UIAll.h>
  4. #include "util.h"
  5.  
  6. /* Define OS2.0 so that OS 1.0 can be checked for. 
  7.    Special processing is required if app not allowed
  8.    to run under PalmOS 1.0 */
  9. #define Version20    sysMakeROMVersion (2, 0, 0, 0, 0)
  10. #define BITS_SET(w,b) (((w) & (b)) == (b))
  11. /* Stuff used to export to MemoPad */
  12. #define firstRecord                   0
  13. #define memoPadAppType          'memo'
  14. #define memoPadDBType           'DATA'
  15. #define memoPadDBName           "MemoDB"
  16. #define memoPadMaxChar          4000
  17.  
  18. /*************************************************************
  19.  *
  20.  * NAME:        Id2Ptr
  21.  *
  22.  * DESCRIPTION: This routine is is used to convert an object ID 
  23.  *              into a pointer to the object.
  24.  *
  25.  * REVISION HISTORY:
  26.  *   Name   Date       Description
  27.  *   ----   --------   -----------
  28.  *   kld    5 Nov 98   Initial Revision
  29.  *
  30.  *************************************************************/
  31. VoidPtr Id2Ptr( Word wID )
  32. {
  33.   return( FrmGetObjectPtr( FrmGetActiveForm(), 
  34.                            FrmGetObjectIndex( FrmGetActiveForm(), wID ) ) );
  35. }
  36.  
  37.  
  38. /*************************************************************
  39.  *
  40.  * NAME:        CheckRomVersion
  41.  *
  42.  * DESCRIPTION: This routine checks that a ROM version meets the
  43.  *              minimum requirement.
  44.  *
  45.  * REVISION HISTORY:
  46.  *   Name   Date       Description
  47.  *   ----   --------   -----------
  48.  *   kld    5 Nov 98   Initial Revision
  49.  *
  50.  *************************************************************/
  51. Err CheckRomVersion(DWord requiredVersion, Word launchFlags)
  52. {
  53.   DWord romVersion;
  54.  
  55.   /* Get the ROM version for which PalmOS version is being used. */
  56.   FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
  57.   if (romVersion >=  requiredVersion)
  58.     return (0);
  59.  
  60.   
  61.   /* If the user launched the app from the launcher, explain
  62.      why the app shouldn't run using FrmAlert. */
  63.   if (BITS_SET(launchFlags, sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
  64.     {
  65.       FrmAlert (RomIncompatibleAlert);
  66.       if (romVersion < Version20)
  67.         {
  68.           Err err;     // Why is this var needed? See <AppLaunchCmd.h>!
  69.           AppLaunchWithCommand(sysFileCDefaultApp,
  70.                                sysAppLaunchCmdNormalLaunch,
  71.                                NULL);
  72.         }
  73.     }
  74.  
  75.   return (sysErrRomIncompatible);
  76. }
  77.  
  78.  
  79. /*************************************************************
  80.  *
  81.  * NAME:        ExportToMemoPad
  82.  *
  83.  * DESCRIPTION: This routine is used to export the string with
  84.  *              the given handle to the memo pad
  85.  *
  86.  * TODO: Check for the string length not to exceed max size
  87.  *       allowed in one memopad record.
  88.  *
  89.  *
  90.  * REVISION HISTORY:
  91.  *   Name   Date       Description
  92.  *   ----   ---------  -----------
  93.  *   kld    25 Nov 98  Initial Revision
  94.  *
  95.  *************************************************************/
  96. Int ExportToMemoPad(VoidHand hndExportText)
  97. {
  98.   UInt record = firstRecord;
  99.   VoidHand hndNew;
  100.   DmOpenRef pdbMemoPad;
  101.   Word length;
  102.   CharPtr sExportText;
  103.  
  104.   /* Open MemoPad database */
  105.   pdbMemoPad = DmOpenDatabaseByTypeCreator(memoPadDBType, memoPadAppType, dmModeReadWrite);
  106.   if (!pdbMemoPad)
  107.     {
  108.       FrmAlert(NoMemoPadAlert);
  109.       return 1;
  110.     }
  111.  
  112.   /* Create New MemoPad record */
  113.   sExportText = (CharPtr) MemHandleLock(hndExportText);
  114.   length = StrLen(sExportText);
  115.   if (length > memoPadMaxChar)
  116.     {
  117.       FrmAlert(ExportSizeAlert);
  118.       return 3;
  119.     }
  120.   record = 0;             // at index 0 in MemoPad database
  121.   hndNew = DmNewRecord(pdbMemoPad, &record, length+1);
  122.  
  123.   if (!hndNew)
  124.     {
  125.       FrmAlert(ErrorExportingAlert);
  126.       return 2;
  127.     }
  128.  
  129.   DmWrite(MemHandleLock(hndNew), 0, MemHandleLock(hndExportText), length+1);
  130.   MemHandleUnlock(hndExportText);
  131.   MemHandleUnlock(hndNew);
  132.   DmReleaseRecord(pdbMemoPad, record, true);
  133.   DmCloseDatabase(pdbMemoPad);
  134.  
  135.   return 0;
  136. }
  137.